<template>
  <div class="loginPage">
    <div class="loginInfo">
     <el-form ref="loginForm" :model="loginUser" label-width="80px" label-position="left" :rules="rules">
      <el-form-item label="用户名" prop="name">
        <el-input placeholder="用户名" clearable v-model="loginUser.name"></el-input>
      </el-form-item>
      <el-form-item label="密码" prop="password">
        <el-input type="password" placeholder="密码" clearable v-model="loginUser.password"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="default" @click="loginFn">登录</el-button>
      </el-form-item>
     </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      loginUser:{},
      rules:{
        name:[
          {
            required:true,
            message:'请输入用户名',
            trigger:'change'//change好一些,它是在一输入数据就去除提醒,blur是在输入并失去焦点后才去除提醒
          }
        ],
        password:[
          {
            required:true,
            message:'请输入密码',
            trigger:'change'
          }
        ]
      }
    }
  },
  methods: {
    loginFn(){
      let validate;
      this.$refs.loginForm.validate((valid)=>{
        validate=valid
      })
      if(!validate){
        return;
      }
      sessionStorage.setItem("token", "autoToken")
      this.$router.replace('/dashboard')
    }
  },
}
</script>

<style>
.loginPage{
  height: 100vh;
  width: 100vw;
  background-color: rgb(166, 196, 242);
  display: flex;
  align-items: center;
  justify-content: center;
}
.loginInfo{
  height: 200px;
  width: 300px;
  background-color: rgb(255, 255, 255);
  border-radius: 8px;
  padding: 20px;
}
</style>